package com.t;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public TryServlet() {
        super();
    }
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter out=resp.getWriter();
		out.print("hi there!");
		System.out.println("01");
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
		Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/abc","root","1234");
		Statement st=con.createStatement();

		st.executeUpdate("DROP TABLE IF EXISTS i;");
		String createi = "create table i(" +
				"at BIGINT UNSIGNED NOT NULL COMMENT 'attachment id'," +
				"ds MEDIUMTEXT NOT NULL COMMENT 'description'," +
				"id BIGINT UNSIGNED NOT NULL COMMENT 'id'," +
				"kn INT UNSIGNED NOT NULL COMMENT 'kind'," +
				"ow BIGINT UNSIGNED NOT NULL COMMENT 'owner id'," +
				"ph BIGINT UNSIGNED NOT NULL COMMENT 'path id'," +
				"rc INT UNSIGNED NOT NULL COMMENT 'ref count'," +
				"rf BIGINT UNSIGNED NOT NULL COMMENT 'ref id'," +
				"rt TINYINT UNSIGNED NOT NULL COMMENT 'rate'," +
				"ta BIGINT UNSIGNED NOT NULL COMMENT 'access time'," +
				"tc BIGINT UNSIGNED NOT NULL COMMENT 'create time'," +
				"tg TEXT NOT NULL COMMENT 'tags'," +
				"tm BIGINT UNSIGNED NOT NULL COMMENT 'modify time'," +
				"tx VARCHAR(255) NOT NULL COMMENT 'text'," +
				"xt MEDIUMTEXT NOT NULL COMMENT 'extra'" +
				") "; 
		st.executeUpdate(createi);
		st.executeUpdate("DROP TABLE IF EXISTS i11;");
		String createi11="create table i11(" +
				"id BIGINT UNSIGNED NOT NULL COMMENT 'id'," +
				"pw VARCHAR(255)NOT NULL COMMENT 'password'," +
				"sl VARCHAR(255) NOT NULL COMMENT 'salt'," +
				"tc BIGINT UNSIGNED NOT NULL COMMENT 'create time'," +
				"tm BIGINT UNSIGNED NOT NULL COMMENT 'modify time'" +
				") ";
		st.executeUpdate(createi11);
		st.executeUpdate("DROP TABLE IF EXISTS i5;");
		String createi5="create table i5(" +
				"ba MEDIUMBLOB NOT NULL COMMENT 'Extension'," +
				"bc MEDIUMINT UNSIGNED NOT NULL COMMENT 'length of blob'," +
				"bo MEDIUMBLOB NOT NULL COMMENT 'blob'," +
				"bt MEDIUMBLOB NOT NULL COMMENT 'bits'," +
				"id BIGINT UNSIGNED NOT NULL COMMENT 'id'" +
				") ";
		st.executeUpdate(createi5);
		st.executeUpdate("DROP TABLE IF EXISTS i6;");
		String createi6="create table i6(" +
				"id BIGINT UNSIGNED NOT NULL COMMENT 'id'," +
				"kn INT UNSIGNED NOT NULL COMMENT 'kind'," +
				"ow BIGINT UNSIGNED NOT NULL COMMENT 'owner id'," +
				"rt TINYINT UNSIGNED NOT NULL COMMENT 'rate'," +
				"tc BIGINT UNSIGNED NOT NULL COMMENT 'create time'," +
				"tg TEXT NOT NULL COMMENT 'tags'," +
				"tm BIGINT UNSIGNED NOT NULL COMMENT 'modify time'" +
				") ";
		st.executeUpdate(createi6);
		st.executeUpdate("DROP TABLE IF EXISTS i7;");
		String createi7="create table i7(" +
				"id BIGINT UNSIGNED NOT NULL COMMENT 'id'," +
				"ow BIGINT UNSIGNED NOT NULL COMMENT 'owner id'," +
				"tc BIGINT UNSIGNED NOT NULL COMMENT 'create time'," +
				"tm BIGINT UNSIGNED NOT NULL COMMENT 'modify time'" +
				") " ;
		st.executeUpdate(createi7);
		st.executeUpdate("DROP TABLE IF EXISTS i9;");
		String createi9="create table i9(" +
				"id BIGINT UNSIGNED NOT NULL COMMENT 'id'," +
				"kn INT UNSIGNED NOT NULL COMMENT 'kind'," +
				"ow BIGINT UNSIGNED NOT NULL COMMENT 'owner id'," +
				"rt TINYINT UNSIGNED NOT NULL COMMENT 'rate'," +
				"tc BIGINT UNSIGNED NOT NULL COMMENT 'create time'," +
				"tg TEXT NOT NULL COMMENT 'tags'," +
				"tm BIGINT UNSIGNED NOT NULL COMMENT 'modify time'" +
				")";
		
			st.executeUpdate(createi9);
		} catch (SQLException e) {
			e.printStackTrace();
		}				


	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}
}
